<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTables extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('user_group', function(Blueprint $table){
			$table->increments('id');
			$table->string('name',  50)->nullable()->defaults('');
			$table->string('model',30);
			$table->integer('parent')->defaults(0)->nullable();
			$table->integer('sort')->defaults(255)->nullable();
		});
		Schema::create('account_type', function(Blueprint $table){
			$table->increments('id');
			$table->string('name',  50)->nullable()->defaults('');
			$table->smallInteger('enable')->default(1)->nullable();
		});
		Schema::create('user', function(Blueprint $table){
			$table->increments('id');
			$table->string('account', 60)->nullable()->defaults('');
			$table->string('password', 60)->nullable()->defaults('');
			$table->integer('user_group_id')->defaults(0)->nullable();//用户组
			$table->integer('account_type_id')->defaults(0)->nullable();//账户类型			
			$table->smallInteger('indie')->default(1)->nullable(); //是否可以独立登陆
			$table->smallInteger('active')->default(0)->nullable();//是否激活			
			$table->string('email',30)->nullable()->defaults('');//邮箱			
			$table->string('avatar',100)->nullable()->defaults('');//头像			
			$table->string('phone',30)->nullable()->defaults('');//电话
			$table->integer('score')->defaults(0)->nullable();//积分
      $table->integer('likes_count')->defaults(0);
      $table->integer('collects_count')->nullable()->defaults(0);
			$table->rememberToken();
			$table->timestamps();
		});
		Schema::create('customer', function(Blueprint $table){
			$table->increments('id');
			$table->integer('user_id')->unique();//用户id
			$table->string('realname', 60)->nullable()->defaults('');//真实姓名
			$table->string('credit',30)->nullable()->defaults('');//身份证
			$table->string('province',100)->nullable()->defaults('');
			$table->string('city',100)->nullable()->defaults('');
			$table->string('district',100)->nullable()->defaults('');
			$table->timestamps();
		});
		Schema::create('lawyer', function(Blueprint $table){
			$table->increments('id');
			$table->integer('user_id')->unique();//用户id
			$table->string('realname', 60)->nullable()->defaults('');//真实姓名
			$table->string('credit',30)->nullable()->defaults('');//身份证
			$table->string('province',100)->nullable()->defaults('');
			$table->string('city',100)->nullable()->defaults('');
			$table->string('district',100)->nullable()->defaults('');
			$table->integer('company_id')->defaults(0)->nullable();//律所id
			$table->string('license', 40)->defaults('')->nullable();//律师证号
			$table->string('license_file', 120)->defaults('')->nullable();//律师扫描文件
			$table->smallInteger('status')->defaults(0)->nullable();//状态
			$table->timestamps();
		});
		Schema::create('company', function(Blueprint $table){ //律师事务所
		    $table->increments('id');
		    $table->integer('user_id');//user id
		    $table->string('name',100)->nullable()->defaults('');;
		    $table->string('province',100)->nullable()->defaults('');
		    $table->string('city',100)->nullable()->defaults('');
		    $table->string('district',100)->nullable()->defaults('');
		    $table->string('address', 100)->nullable()->defaults('');//详细地址
		    $table->string('contact', 30)->nullable()->defaults('');//联系人
		    $table->string('manager', 30)->nullable()->defaults('');//负责人
		    $table->string('license', 40)->defaults('')->nullable();//律师证号
		    $table->string('license_file', 120)->defaults('')->nullable();//律师扫描文件
		    $table->text('scope')->defaults('')->nullable();
			$table->text('introduce')->defaults('')->nullable();
		    $table->smallInteger('status')->defaults(0)->nullable();//状态
		    $table->timestamps();
		});
		Schema::create('activation', function (Blueprint $table){
			$table->increments('id');
			$table->string('token', 40);
			$table->string('email', 30)->nullable()->defaults('');
			$table->string('mobile', 30)->nullable()->defaults('');
			$table->integer('expired');//过期时间
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('user');
		Schema::drop('user_group');
		Schema::drop('account_type');
		Schema::drop('customer');
		Schema::drop('company');		
		Schema::drop('lawyer');
		Schema::drop('activation');
	}

}
